<html>

<head>
<title>Multi-Worker Test</title>

<script src="worker_utils.js"></script>

<script>

var expected_total = 0;
var actual_total = 0;
var completed_worker_count = 0;
var total_workers = 4;

function createWorker(base) {
  var worker = getWorker("worker_common.js");
  for (var i = 0; i < 100; i++) {
    worker.postMessage("eval " + base + "+" + i);
    expected_total += base + i;
  }
  worker.postMessage("ping");
  worker.onmessage = function(evt) {
    if (evt.data == "pong") {
      completed_worker_count++;
      if (completed_worker_count == total_workers) {
        if (expected_total == actual_total)
          onSuccess();
        else
          onFailure();
      }
    } else {
      try {
        actual_total += parseInt(evt.data);
      } catch (ex) {
        onFailure();
      }
    }
  }
  return worker;
}

for (var i = 0; i < total_workers; ++i) {
  var worker = createWorker(100 + i);
}

</script>
</head>

<body>
<div id=statusPanel></div>
</body>
</html>
